import pytest
from selenium import webdriver
from selenium.webdriver.common.by import By
from time import sleep
from Buiness.LoginPage1 import LoginPage1
from Buiness.MainPage import MainPage
from common.log_tools import log
from common.yaml_tools import YamlTools
from Buiness.Member import Member
class TestOA:
    # testdata = [{"username":"123456","password":"123456","expect":"签退","type":"正向"},
    #             {"username"="46465465465456","name"="fefefefeffefefe","mm"="123456","MM"="123456","num"="5964687984654@qq.com","expect":"用户名不能为空。;用户名应当为字母或数字的组合，至少三位","type":"反向"},
    #             {"username":"123456","password":"","expect":"登录失败，请检查您的成员名或密码是否填写正确。","type":"反向"}
    #             ]
#     @pytest.fixture()
#     def get_driver(self):
#         driver = webdriver.Chrome()
#         driver.get("http://localhost/ranzhi/www/crm/customer-browse.html")
#         yield driver
#         driver.quit()
# testdata = [("123456","123456","签退"),
#             ("","123456","登录失败，请检查您的成员名或密码是否填写正确。"),
#             ("123456","","登录失败，请检查您的成员名或密码是否填写正确。"),
#             ("sdadadadwdsada","","登录失败，请检查您的成员名或密码是否填写正确。")
#            ]
    testdata = YamlTools.read_yaml_file("test.yaml")
    @pytest.mark.parametrize("testdata",testdata)
    @pytest.mark.run()
    def test_login(self,get_driver,testdata):
        try:
          mg = Member(driver=get_driver)
          mg.test_member(username=testdata["username"],name=testdata["name"],mm=testdata["mm"],MM=testdata["MM"],num=testdata["num"])
          if testdata["type"]=="正向":
              mg=Member(driver=get_driver)
              assert mg.get_assert_text1() == testdata["expect1"],"登陆失败"
          else:
              assert mg.get_assert_text() == testdata["expect"],"登陆失败"
        except AssertionError as e:
          log.error(e)
          raise e